// did
type int = number;
//class ArrayUtil

export class ArrayUtil {
  public static removeItem<T>(arg1: Array<T>, arg2: T): boolean {
    var loc1 = arg1.length;
    var loc2 = 0;
    while (loc2 < loc1) {
      if (arg1[loc2] == arg2) {
        arg1.splice(loc2, 1);
        return true;
      }
      ++loc2;
    }
    return false;
  }

  public static removeArray<T>(arg1: Array<T>, arg2: Array<T>): void {
    var loc1 = arg2.length;
    var i = 0;
    while (i < loc1) {
      ArrayUtil.removeItem(arg1, arg2[i]);
      ++i;
    }
  }

  public static merge(
    arg1: Array<any>,
    arg2: Array<any>,
    arg3: any,
    arg4: any,
    arg5: int = 0
  ): Array<any> {
    var loc1 = null;
    var loc2 = null;
    var loc3 = null;
    var loc7 = 0;
    var loc8 = 0;
    if (!arg1 || arg1.length == 0) {
      loc1 = arg2;
      var loc9 = 0;
      var loc10 = loc1;
      label148: for (loc3 of loc10) {
        var loc11 = arg5;
        switch (loc11) {
          case ArrayUtil.MergeType_Sub: {
            loc3[arg4] = -loc3[arg4];
            continue label148;
          }
        }
      }
      return loc1;
    }
    if (!arg2 || arg2.length == 0) {
      return (loc1 = arg1);
    }
    if (!arg3) {
      return (loc1 = arg1.concat(arg2));
    }
    var loc4 = [];
    var loc5 = [];
    if (!loc1) {
      loc1 = [];
    }
    var loc6 = 0;
    while (loc6 < arg1.length) {
      if ((loc2 = arg1[loc6]).hasOwnProperty(arg3)) {
        loc7 = 0;
        while (loc7 < arg2.length) {
          loc3 = arg2[loc7];
          if (loc5.indexOf(loc7) == -1 && loc4.indexOf(loc7) == -1) {
            loc5.push(loc7);
          }
          if (loc3.hasOwnProperty(arg3)) {
            if (loc2[arg3] == loc3[arg3]) {
              if (loc4.indexOf(loc7) == -1) {
                loc4.push(loc7);
              }
              if (loc5.indexOf(loc7) != -1) {
                loc5.splice(loc5.indexOf(loc7), 1);
              }
              loc9 = arg5;
              switch (loc9) {
                case ArrayUtil.MergeType_Plus: {
                  loc2[arg4] = loc2[arg4] + loc3[arg4];
                  break;
                }
                case ArrayUtil.MergeType_Sub: {
                  loc2[arg4] = loc2[arg4] - loc3[arg4];
                  break;
                }
                case ArrayUtil.MergeType_Replace: {
                  loc2[arg4] = loc3[arg4];
                  break;
                }
              }
            }
          }
          ++loc7;
        }
        loc1.push(loc2);
      }
      ++loc6;
    }
    if (loc5.length > 0) {
      loc9 = 0;
      loc10 = loc5;
      for (loc8 of loc10) {
        loc3 = arg2[loc8];
        if (arg5 == ArrayUtil.MergeType_Sub) {
          loc3[arg4] = -loc3[arg4];
        }
        loc1.push(loc3);
      }
    }
    return loc1;
  }

  public static soryNumberAry(arg1: Array<any>, arg2: Boolean = true): void {
    if (arg2) {
      arg1.sort(ArrayUtil.sortDesc);
    } else {
      arg1.sort(ArrayUtil.sortAsc);
    }
    return;
  }

  /* internal  */ static sortDesc(arg1: number, arg2: number): int {
    if (arg1 > arg2) {
      return -1;
    }
    if (arg1 < arg2) {
      return 1;
    }
    return 0;
  }

  /* internal  */ static sortAsc(arg1: number, arg2: number): int {
    if (arg1 > arg2) {
      return 1;
    }
    if (arg1 < arg2) {
      return -1;
    }
    return 0;
  }

  public static equips(arg1: Array<any>, arg2: Array<any>): Boolean {
    var loc2 = 0;
    if (arg1 == null || arg2 == null) {
      return false;
    }
    if (arg1.length != arg2.length) {
      return false;
    }
    var loc1 = arg1.length;
    loc2 = 0;
    while (loc2 < loc1) {
      if (arg1[loc2] != arg2[loc2]) {
        return false;
      }
      ++loc2;
    }
    return true;
  }

  public static /* const */ MergeType_Plus: int = 1;

  public static /* const */ MergeType_Sub: int = 2;

  public static /* const */ MergeType_Replace: int = 3;
}
